/********************************************************************
 * PROJECT: CSAIR ROST PROJECT.
 * SUPPLIER: FOREVER OPEN SOURCE SOFTWARE INC.
 ********************************************************************
 * FILE: GanttItem.java
 * (C) Copyright Foliage Team 2013, All Rights Reserved.
 ********************************************************************/
package org.foliage.rcp.ui.widgets;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Item;

@SuppressWarnings({ "rawtypes", "unchecked" })
public class GanttItem extends Item {

	// ----------------------------------------------- 

	private Rectangle bounds;

	private boolean visible = true;

	private final List tasks = new ArrayList();

	private final Gantt parent;

	// ----------------------------------------------- 

	public GanttItem(Gantt parent, int style) {
		this(parent, style, -1);
	}

	public GanttItem(Gantt parent, int style, int index) {
		super(parent, style, index);
		this.parent = parent;
		this.parent.newItem(this, index);
	}

	// ----------------------------------------------- 

	@Override
	public void dispose() {
		parent.removeItem(this);
		super.dispose();
	}

	// ----------------------------------------------- 

	void newTask(GanttTask task, int index) {
		if (index == -1) {
			tasks.add(task);
		} else {
			tasks.add(index, task);
		}
		this.parent.newTask(task, index);
	}

	// ----------------------------------------------- 

	public void setBounds(Rectangle bounds) {
		this.bounds = bounds;
	}

	public Rectangle getBounds() {
		return bounds;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
		this.parent.redraw();
	}

	// -----------------------------------------------

	public void addTask(GanttTask task) {
		tasks.add(task);
	}

	public void removeTask(GanttTask task) {
		tasks.remove(task);
	}

	public GanttTask[] getTasks() {
		return (GanttTask[]) tasks.toArray(new GanttTask[tasks.size()]);
	}

}
